/*!
\copyright  Copyright (c) 2023 Qualcomm Technologies International, Ltd.
            All Rights Reserved.
            Qualcomm Technologies International, Ltd. Confidential and Proprietary.
\file
\brief      Clock hints for DSPs that control their own clock.

*/

#include <operator.h>
#include <logging.h>

#include <stdint.h>

#define DSP_CLOCK_POWER_MODE_KEY 0x9
#define DSP_CLOCK_POWER_MODE_MAX 100
#define DSP_CLOCK_POWER_MODE_AUTO 200

static uint16_t dsp_clock_max_count;

inline static void dspClock_Set(uint16_t dsp_clock)
{
    OperatorFrameworkConfigurationSet(DSP_CLOCK_POWER_MODE_KEY, &dsp_clock, sizeof(dsp_clock)/sizeof(uint16_t));
}

void DspClock_Max(void)
{
    DEBUG_LOG_VERBOSE("DspClock_Max: dsp_clock_max_count=%u", dsp_clock_max_count);
    if (dsp_clock_max_count == 0)
    {
        dspClock_Set(DSP_CLOCK_POWER_MODE_MAX);
    }
    dsp_clock_max_count++;
}

void DspClock_Auto(void)
{
    DEBUG_LOG_VERBOSE("DspClock_Auto: dsp_clock_max_count=%u", dsp_clock_max_count);
    if(dsp_clock_max_count > 0)
    {
        dsp_clock_max_count--;
    }
    if(dsp_clock_max_count == 0)
    {
        DEBUG_LOG_VERBOSE("DspClock_Auto: Setting to Auto");
        dspClock_Set(DSP_CLOCK_POWER_MODE_AUTO);
    }
}
